package com.wise.service.local.content.code;

import com.wise.framework.consts.Consts;
import com.wise.summer.v1.local.content.verificationcode.CheckSetSmsSended;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.concurrent.TimeUnit;

@Service
@SummerService
public class CheckSetSmsSendedService implements SummerServiceBean<CheckSetSmsSended> {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public void sum(CheckSetSmsSended summer) {
        String key = Consts.REDIS_MOBILE_VERIFY_SEND_TIME_KEY + summer.getUseType() +"-"  + summer.getMobile();
        Boolean hasKey = redisTemplate.hasKey(key);

        if(null == hasKey || hasKey){
            summer.setSummerResult(false);
            return;
        }

        ValueOperations<String, String> opt = redisTemplate.opsForValue();
        opt.set(key, "1", 1, TimeUnit.MINUTES);

        summer.setSummerResult(true);

    }
}
